<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery-3.5.1.min.js"></script>
    <style>
        body {
            background-color: pink;
        }

        div {
            width: 420px;
            height: 340px;
            border: 1px solid #f1eded;
            margin: 200px auto;
            background-color: #f1eded;
        }

        p {
            font-size: 31px;
            text-align: center;
            color: #ef3a3b;
            margin: 70px auto;
        }

        span {
            display: inline-block;
            width: 40px;
            height: 40px;
            background-color: #333;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 40px;
            margin: 40px auto;
        }

        .time {
            color: #333;
            background-color: #f1eded;
        }
    </style>
</head>

<body>
    <audio src="Brand New Day.mp3" autoplay="autoplay" loop="loop"></audio>
    <div>
        <p>距离考试还有</p>
        <span class="day" style="margin-left: 48px;"></span>
        <span class="time">天</span>
        <span class="hour"></span>
        <span class="time">时</span>
        <span class="minute"></span>
        <span class="time">分</span>
        <span class="second"></span>
        <span class="time">秒</span>
    </div>
    <script>
        var inputTime = +new Date('2021-05-30 00:00:00');
        getTime();
        // 开启定时器
        setInterval(getTime, 1000);
        function getTime() {
            var nowTime = +new Date();
            var times = (inputTime - nowTime) / 1000;
            // 天
            var d = parseInt(times / 60 / 60 / 24);
            d = d < 10 ? '0' + d : d;
            $(".day").text(d);
            // 时
            var h = parseInt(times / 60 / 60 % 24);
            h = h < 10 ? '0' + h : h;
            $(".hour").text(h);
            // 分
            var m = parseInt(times / 60 % 60);
            m = m < 10 ? '0' + m : m;
            $(".minute").text(m);
            // 秒
            var s = parseInt(times % 60);
            s = s < 10 ? '0' + s : s;
            $(".second").text(s);
        }
    </script>
</body>

</html>